﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;

namespace BZZ.Web.blog
{
    public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            showInfoList();

        }


        #region 信息列表和查询
        /// <summary>
        /// 数据列表
        /// </summary>
        protected void showInfoList()
        {
            #region 变量定义
            DataSet dset = new DataSet();
            BZZ.DAL.blog dal = new BZZ.DAL.blog();
            System.Collections.Generic.List<System.Data.SqlClient.SqlParameter> paraList = new List<System.Data.SqlClient.SqlParameter>();
            string dataFields = ""; //读取的字段名，空为所有
            string strWhere = "1=1"; //查询子句
            string strOrderBy = " id desc"; //排序参数，如果需要分页，则必填 
            #endregion

            #region 查询条件
            //string strId = txtQryId.Text.Trim();
            //if (strId != "" && strId != null )
            //{
            //    strWhere += " and id=@id";
            //    paraList.Add(new System.Data.SqlClient.SqlParameter("@id", strId));
            //} 
            string strCataid = Request.QueryString["cataid"];
            if (strCataid != null && strCataid != "")
            {
                strWhere += " and cataid=@cataid";
                paraList.Add(new System.Data.SqlClient.SqlParameter("@cataid", strCataid));
            }
            //string strSubcataid = txtQrySubcataid.Text.Trim();
            //if (strSubcataid != null && strSubcataid != "")
            //{
            //    strWhere += " and subcataid=@subcataid";
            //    paraList.Add(new System.Data.SqlClient.SqlParameter("@subcataid", strSubcataid));
            //}

            string strStatus = "1";
            if (strStatus != "" && strStatus != null)
            {
                strWhere += " and status=@status";
                paraList.Add(new System.Data.SqlClient.SqlParameter("@status", strStatus));
            } 
            //string strExt1 = txtQryExt1.Text.Trim();
            //if (strExt1 != "" && strExt1 != null )
            //{
            //    strWhere += " and ext1=@ext1";
            //    paraList.Add(new System.Data.SqlClient.SqlParameter("@ext1", strExt1));
            //} 
            //string strExt2 = txtQryExt2.Text.Trim();
            //if (strExt2 != "" && strExt2 != null )
            //{
            //    strWhere += " and ext2=@ext2";
            //    paraList.Add(new System.Data.SqlClient.SqlParameter("@ext2", strExt2));
            //} 
            #endregion

            #region 分页控件绑定
            int pageSize = 30; //分页每页记录个数
            int totalRecourd = 0; //总记录个数
            int currentPage = 1; //当前页码
            try { currentPage = int.Parse(Request.QueryString["p"]); }
            catch { }

            totalRecourd = dal.GetCount(strWhere, paraList);
            dset = dal.GetDatasetByPageSql(currentPage, pageSize, strWhere, strOrderBy, paraList, dataFields);
            if (dset != null && dset.Tables[0].Rows.Count > 0)
            {
                rptInfoList.DataSource = dset;
                rptInfoList.DataBind();
                //litPager.Text = LIB.pager.getFrontPager(this, totalRecourd, pageSize);
                
            }
            #endregion

        }

        public string showSumary(string content,string id)
        {
            string rtn = content;
            content = content.Replace("<strong>", "").Replace("</strong>", "");
            if (content.Length > 305) rtn = content.Substring(0, 300) + "…………<p><a href=\"/blog/blogDetail.aspx?id=" + id + "\" target=\"_blank\">阅读全文</a></P>";
            return rtn;
        }

        public int getCommentCount(object blogid)
        {
            int id = Convert.ToInt32(blogid);
            BZZ.DAL.blogComment dal = new BZZ.DAL.blogComment();
            return dal.GetCount("blogid=" +id.ToString(), null);
        }
        #endregion

    }
}
